package dao;

import domain.Emp;
import utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class EmpUpdateDaoImp implements EmpUpdateDao {
    @Override
    public void updateEmp(Emp emp) {
        Connection conn=null;
        PreparedStatement sta=null;
        try {
            conn= JdbcUtils.getConnection();
            //编写sql语句
            String sql="update t_emp set ename=?,age=?,sex=?,sal=?,birthday=?,edate=? where id=?";
            sta=conn.prepareStatement(sql);
            //设置值
            sta.setInt(7,emp.getId());
            sta.setString(1,emp.getEname());
            sta.setInt(2,emp.getAge());
            sta.setString(3,emp.getSex());
            sta.setDouble(4,emp.getSal());
            sta.setString(5,emp.getBirthday());
            sta.setString(6,emp.getEdate());
            //修改数据
            sta.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close(conn,sta);
        }
    }
}
